#include "stdafx.h"
#include "Utilities.h"

using namespace std;

namespace ZeEngine
{
    bool Utilities::GetAttributeString(const tinyxml2::XMLElement* pElement, const std::string& strAttributeName, std::string& value)
    {
        bool fSuccess = false;

        if (pElement)
        {
            const char* pValue = pElement->Attribute(strAttributeName.c_str());

            if (pValue)
            {
                value = pValue;
                fSuccess = true;
            }
        }

        return fSuccess;
    }

    bool Utilities::PointInRectangleTest(const Vector2D<float>& point, const SDL_Rect& rect)
    {
        bool fInside = false;
        if (point.GetX() >= rect.x && point.GetX() <= (rect.x + rect.w))
        {
            if (point.GetY() >= rect.y && point.GetY() <= (rect.y + rect.h))
            {
                fInside = true;
            }
        }

        return fInside;
    }

    bool Utilities::RectangleCollisionTest(const SDL_Rect& a, const SDL_Rect& b)
    {
        return !(a.x + a.w <= b.x || a.y + a.h <= b.y || a.x >= b.x + b.w || a.y >= b.y + b.h);
    }     

	bool Utilities::RectangleCollisionTestStrict(const SDL_Rect& a, const SDL_Rect& b)
	{
		return !(a.x + a.w < b.x || a.y + a.h < b.y || a.x > b.x + b.w || a.y > b.y + b.h);
	}
}
